#include "timelineview.h"

#include <QScrollBar>
#include <QTableView>
#include <QObject>
#include <QDebug>
#include <QFileInfo>
#include <QMimeData>
#include <QPainter>

#include "timelineitem.h"

const int TITLE_HEIGHT = 35;
const int VIEW_HEIGHT = 400;
const int BUTTON_WIDTH = 16;
const int BUTTON_HEIGHT = 16;
const int ICON_WIDTH = 96;
const int ICON_HEIGHT = 96;
const int PLAY_ICON_WIDTH = 36;
const int PLAY_ICON_HEIGHT = 36;
const int UPPER_LEFT_POINT_WIDTH = 30;
const int UPPER_LEFT_POINT_HEIGHT = 30;
const int SLIDER_RANGE_DENOMINATOR = 3;
const int SLIDER_RANGE_MOLECULE = 2;
const int INIT_NEW_VIEW_COUNT = 20;
const int NEW_COUNT = 0;
const int ICON_MODE_SELECT_BUTTON = 14;

TimeLineView::TimeLineView(int itemName, QWidget *parent) : QWidget(parent)
{
    this->setAcceptDrops(true);
    m_itemName = itemName;
    if (itemName == LIST_TYPE::PICTURE || itemName == LIST_TYPE::QQPICTURE
        || itemName == LIST_TYPE::WECHATPICTURE) { // Picture图片
        initTimeLineViewWidget();
    } else if (itemName == LIST_TYPE::VIDEO || itemName == LIST_TYPE::QQVIDEO
               || itemName == LIST_TYPE::WECHATVIDEO) { // Video视频
        initTimeLineViewWidget();
    } else if (itemName == LIST_TYPE::MUSIC || itemName == LIST_TYPE::QQMUSIC
               || itemName == LIST_TYPE::WECHATMUSIC) { // Music音乐
        initViewWidget();
    } else if (itemName == LIST_TYPE::DOCUMENT || itemName == LIST_TYPE::QQDOCUMENT
               || itemName == LIST_TYPE::WECHATDOCUMENT) { // Document文档
        initViewWidget();
    }
}

TimeLineView::~TimeLineView()
{
    if (m_pictureListWidget != nullptr) {
        m_pictureListWidget->deleteLater();
        m_pictureListWidget = nullptr;
    }
}

void TimeLineView::initTimeLineViewWidget()
{
    QVBoxLayout *mainVLayout = new QVBoxLayout();
    mainVLayout->setContentsMargins(0, 0, 0, 0);
    this->setLayout(mainVLayout);

    m_pictureListWidget = new TimeLineListWidget();
    //    QScrollBar *pHorizontalBar = m_pictureListWidget->horizontalScrollBar();
    //    pHorizontalBar->setEnabled(false);
    //    pHorizontalBar->setVisible(false);
    m_pictureListWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);

    //设置滑动步长
    m_pictureListWidget->setVerticalScrollMode(QListWidget::ScrollPerPixel);
    m_pictureListWidget->verticalScrollBar()->setSingleStep(20);
    mainVLayout->addWidget(m_pictureListWidget);
    m_pictureListWidget->setFrameShape(QTableView::NoFrame);
    connect(m_pictureListWidget->verticalScrollBar(), &QScrollBar::valueChanged, this, &TimeLineView::slotValueChanged);
}

void TimeLineView::setTheme(PublicAttributes::Theme theme)
{
    if (theme == PublicAttributes::Theme::Light) {
        if (m_pictureListWidget != nullptr) {
            QPalette listWidgetPalette = this->palette();
            listWidgetPalette.setColor(QPalette::Base, QColor("#FFFEFD"));
            this->setPalette(listWidgetPalette);
        } else {
            QPalette listWidgetPalette = this->palette();
            listWidgetPalette.setColor(QPalette::Base, QColor("#FFFEFD"));
            this->setPalette(listWidgetPalette);
        }
    } else if (theme == PublicAttributes::Theme::Dark) {
        if (m_pictureListWidget != nullptr) {
            QPalette listWidgetPalette = this->palette();
            listWidgetPalette.setColor(QPalette::Base, QColor("#1D1D1D"));
            this->setPalette(listWidgetPalette);
        } else {
            QPalette listWidgetPalette = this->palette();
            listWidgetPalette.setColor(QPalette::Base, QColor("#1D1D1D"));
            this->setPalette(listWidgetPalette);
        }
    }
}

void TimeLineView::initViewWidget()
{

}

void TimeLineView::setMusicDateWidget()
{
    MobileFileListView *listView = new MobileFileListView();
    QVBoxLayout *vLayout = new QVBoxLayout;
    vLayout->addWidget(listView);
    vLayout->addStretch();
    setLayout(vLayout);
    //默认图标模式QListView::IconMode
    listView->setViewModeFlag(QListView::IconMode, m_listStruct);

    //设置列表模式
    connect(this, &TimeLineView::signalViewModeFlag, listView, [=](QListView::ViewMode mode) {
        listView->setViewModeFlag(mode, m_listStruct);
        //设置高度
        listView->setResize();
    });

    //设置view的高度
    connect(listView, &MobileFileListView::signalSetResize, this, [=](int height) {
        listView->setFixedHeight(height);
//        if (height >= 0 && height <= VIEW_HEIGHT) {
//            listView->setFixedHeight(VIEW_HEIGHT);
//        }
    });

    listView->setTimeLineViewData(m_listStruct, m_itemMap);
    listView->setResize();

    connect(listView, &MobileFileListView::sigShowCopyButton, this, &TimeLineView::slotShowCopyButton);

    connect(listView, &MobileFileListView::sigHideCopyToComputerWidget, this,
            &TimeLineView::slotHideCopyToComputerWidget);

    connect(listView, &MobileFileListView::sigSelectDataList, this, &TimeLineView::slotSelectDataList);

    connect(listView, &MobileFileListView::sigMousePress, this, [=]() {
        Q_EMIT sigHideCopyToComputerWidget();
    });

    connect(listView, &MobileFileListView::sigMouseRelease, this, [=]() {
        QList<FileInfo> list;
        listView->selectAllNames(list);
        if (list.length() > 0) {
            Q_EMIT sigShowCopyButton();
        } else if (list.length() == 0) {
            Q_EMIT sigHideCopyToComputerWidget();
        }
    });

    connect(listView, &MobileFileListView::sigSelectAll, this, [=]() {
        Q_EMIT sigShowCopyButton();
    });

    connect(listView, &MobileFileListView::sigMenuFilePath, this, [=](QString filePath) {
        Q_EMIT sigMenuFilePath(filePath);
    });

    connect(this, &TimeLineView::sigSetViewHeight, listView, [=]() {
        listView->setViewHeight();
    });

    Q_EMIT sigItemInitFinish();
}

void TimeLineView::setDocumentDateWidget()
{
    MobileFileListView *listView = new MobileFileListView();
    QVBoxLayout *vLayout = new QVBoxLayout;
    vLayout->addWidget(listView);
    vLayout->addStretch();
    setLayout(vLayout);
    listView->setViewModeFlag(QListView::IconMode, m_listStruct);

    //设置列表模式
    connect(this, &TimeLineView::signalViewModeFlag, listView, [=](QListView::ViewMode mode) {
        listView->setViewModeFlag(mode, m_listStruct);
        //设置高度
        listView->setResize();
    });

    //设置view的高度
    connect(listView, &MobileFileListView::signalSetResize, this, [=](int height) {
        listView->setFixedHeight(height);
        //设置QListView所在界面的高度，防止当view的高度过小，对上传有影响
//        if (height >= 0 && height <= VIEW_HEIGHT) {
//            listView->setFixedHeight(VIEW_HEIGHT);
//        }
    });

    listView->setTimeLineViewData(m_listStruct, m_itemMap);
    listView->setResize();

    connect(listView, &MobileFileListView::sigShowCopyButton, this, &TimeLineView::slotShowCopyButton);

    connect(listView, &MobileFileListView::sigHideCopyToComputerWidget, this,
            &TimeLineView::slotHideCopyToComputerWidget);

    connect(listView, &MobileFileListView::sigSelectDataList, this, &TimeLineView::slotSelectDataList);

    connect(listView, &MobileFileListView::sigMousePress, this, [=]() {
        Q_EMIT sigHideCopyToComputerWidget();
    });


    connect(listView, &MobileFileListView::sigMouseRelease, this, [=]() {
        QList<FileInfo> list;
        listView->selectAllNames(list);
        if (list.length() > 0) {
            Q_EMIT sigShowCopyButton();
        } else if (list.length() == 0) {
            Q_EMIT sigHideCopyToComputerWidget();
        }
    });

    connect(listView, &MobileFileListView::sigSelectAll, this, [=]() {
        Q_EMIT sigShowCopyButton();
    });

    connect(listView, &MobileFileListView::sigMenuFilePath, this, [=](QString filePath) {
        Q_EMIT sigMenuFilePath(filePath);
    });

    connect(this, &TimeLineView::sigSetViewHeight, listView, [=]() {
        listView->setViewHeight();
    });

    Q_EMIT sigItemInitFinish();
}

void TimeLineView::setPictureTimeLineDateWidget()
{
    //当前时间线
    QString currentPictureTimeLine;
    //当前时间线的照片
    QList<FileInfo> currentTimeLinePicture;
    //保存时间线的图片
    QList<QList<FileInfo>> saveCurrentTimeLinePicture;

    int currentPictureTimeLineLoad = 0;

    for (int i = 0; i < m_listStruct.size(); i++) {
        if (m_listStruct.size() == 1) {
            currentPictureTimeLine = m_listStruct.value(i).getDate();
            m_allPictureTimeLine << currentPictureTimeLine;
            currentTimeLinePicture << m_listStruct.value(i);
            saveCurrentTimeLinePicture << currentTimeLinePicture;
            m_allTimeLinePicture << saveCurrentTimeLinePicture;
        } else if (m_listStruct.size() > 1) {
            if (i == 0) {
                currentPictureTimeLine = m_listStruct.value(i).getDate();
                m_allPictureTimeLine << currentPictureTimeLine;
                currentTimeLinePicture << m_listStruct.value(i);
                if (m_listStruct.value(i).getDate() != m_listStruct.value(i + 1).getDate()) {
                    saveCurrentTimeLinePicture << currentTimeLinePicture;
                    m_allTimeLinePicture << saveCurrentTimeLinePicture.value(currentPictureTimeLineLoad);
                }
            } else if (i > 0) {
                if (m_listStruct.value(i - 1).getDate() == m_listStruct.value(i).getDate()) {
                    if (i < m_listStruct.size() - 1) {
                        if (m_listStruct.value(i).getDate() != m_listStruct.value(i + 1).getDate()) {
                            currentTimeLinePicture << m_listStruct.value(i);
                            saveCurrentTimeLinePicture << currentTimeLinePicture;
                            m_allTimeLinePicture << saveCurrentTimeLinePicture.value(currentPictureTimeLineLoad);
                        } else {
                            currentTimeLinePicture << m_listStruct.value(i);
                        }
                    }
                    if (i == m_listStruct.size() - 1) {
                        currentTimeLinePicture << m_listStruct.value(i);
                        saveCurrentTimeLinePicture << currentTimeLinePicture;
                        m_allTimeLinePicture << saveCurrentTimeLinePicture.value(currentPictureTimeLineLoad);
                    }
                } else {
                    currentPictureTimeLineLoad++;
                    currentPictureTimeLine = m_listStruct.value(i).getDate();
                    m_allPictureTimeLine << currentPictureTimeLine;
                    currentTimeLinePicture.clear();
                    currentTimeLinePicture << m_listStruct.value(i);
                    if (i < m_listStruct.size() - 1) {
                        if (m_listStruct.value(i).getDate() != m_listStruct.value(i + 1).getDate()) {
                            saveCurrentTimeLinePicture << currentTimeLinePicture;
                            m_allTimeLinePicture << saveCurrentTimeLinePicture.value(currentPictureTimeLineLoad);
                        }
                    }
                    if (i == m_listStruct.size() - 1) {
                        saveCurrentTimeLinePicture << currentTimeLinePicture;
                        m_allTimeLinePicture << saveCurrentTimeLinePicture.value(currentPictureTimeLineLoad);
                    }
                }
            }
        }
    }

    m_startCount = NEW_COUNT;
    m_endCount = INIT_NEW_VIEW_COUNT;
    if (m_endCount > m_allPictureTimeLine.size()) {
        m_endCount = m_allPictureTimeLine.size();
        disconnect(m_pictureListWidget->verticalScrollBar(), &QScrollBar::valueChanged, this,
                   &TimeLineView::slotValueChanged);
    }

    setTimeLineData();
    Q_EMIT sigItemInitFinish();
}

void TimeLineView::setTimeLineData()
{
    for (int i = m_startCount; i < m_endCount; i++) {
        QWidget *titleWidget = new QWidget(this);
        titleWidget->setFixedHeight(TITLE_HEIGHT);
        QHBoxLayout *titleHLayout = new QHBoxLayout();
        titleWidget->setLayout(titleHLayout);
//        //复选框
//        QCheckBox *checkBox = new QCheckBox(this);
//        checkBox->setCursor(Qt::PointingHandCursor);
//        checkBox->setFixedSize(BUTTON_WIDTH, BUTTON_HEIGHT);
//        m_allPictureCheckBox << checkBox;

        //时间
        m_pictureDate = new QLabel(this);

        QStringList dateList = m_allPictureTimeLine.value(i).split("-");
        QString date;
        if (dateList.count() > 2) {
            date = QString(tr("%1/%2/%3")).arg(dateList[0]).arg(dateList[1]).arg(dateList[2]); //%1/%2/%3
        }
        m_pictureDate->setText(date);

        //个数
        m_pictureNum = new QLabel(this);
        QString sum = QString("(%1)").arg(m_allTimeLinePicture.value(i).size());
        m_pictureNum->setText(sum);

        //箭头线button
        ArrowLineButton *arrowLineButton = new ArrowLineButton();
        arrowLineButton->setIcon(QIcon(":/png/image/arrow_line_expand.png"));
        arrowLineButton->setCursor(Qt::PointingHandCursor);
        arrowLineButton->setFixedSize(BUTTON_WIDTH, BUTTON_HEIGHT);
        arrowLineButton->setFlat(true);
        m_allPictureArrowLineButton << arrowLineButton;
        m_allPictureAllow << 0;

        QListWidgetItem *item = new QListWidgetItem();
        TimeLineItem *itemWidget = new TimeLineItem(this);

        QVBoxLayout *timeLineLayout = new QVBoxLayout();
        itemWidget->setLayout(timeLineLayout);

        QHBoxLayout *viewHLayout = new QHBoxLayout();
        MobileFileListView *listView = new MobileFileListView();
        viewHLayout->addWidget(listView);
//        titleHLayout->addWidget(checkBox);
//        titleHLayout->addSpacing(10);
        viewHLayout->setContentsMargins(0, 18, 0, 0);
        titleHLayout->addWidget(m_pictureDate);
        titleHLayout->addSpacing(15);
        titleHLayout->addWidget(m_pictureNum);
        titleHLayout->addStretch();
        titleHLayout->addWidget(arrowLineButton);
        titleHLayout->addSpacing(26);
        titleHLayout->setSpacing(0);
        titleHLayout->setMargin(0);
        titleHLayout->setContentsMargins(0, 0, 0, 0);

        //复选框的点击
//        connect(checkBox, &QCheckBox::clicked, this, [=]() {
//            checkBox->setTristate(false);
//            if (checkBox->isChecked()) {
//                listView->selectAll();
//                QList<FileInfo> fileList;
//                for (int j = 0; j < m_allPictureListView.size(); j++) {
//                    QList<FileInfo> list;
//                    m_allPictureListView[j]->selectAllNames(list);
//                    fileList.append(list);
//                }
//                Q_EMIT sigSelectDataList(fileList);
//                Q_EMIT sigShowCopyButton();
//            } else {
//                QList<FileInfo> list;
//                listView->selectAllNames(list);
//                listView->clearSelection();
//                for (int j = 0; j < listView->model()->rowCount(); j++) {
//                    QModelIndex index = listView->model()->index(j, 0, QModelIndex());
//                    FileInfo fileInfo = index.data(Qt::DisplayRole + 100).value<FileInfo>();
//                    list.append(fileInfo);
//                }

//                for (int j = 0; j < list.size(); j++) {
//                    if (list.value(j).type() == FileInfo::FILE_TYPE::TYPE_IMAGE) {
//                        QStandardItem *item = m_itemMap.find(list.value(j).getThumbnailPath()).value();
//                        QString localImagePath = QString("%1").arg(list.value(j).getThumbnailPath());
//                        QPixmap pixmap(localImagePath);
//                        pixmap = pixmap.scaled(QSize(ICON_WIDTH, ICON_HEIGHT), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
//                        item->setIcon(pixmap);
//                    } else if (list.value(j).type() == FileInfo::FILE_TYPE::TYPE_VIDEO) {
//                        QStandardItem *item = m_itemMap.find(list.value(j).getThumbnailPath()).value();
//                        QPixmap pixmap = QString("%1").arg(list.value(j).getThumbnailPath());
//                        pixmap = pixmap.scaled(QSize(ICON_WIDTH, ICON_HEIGHT), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
//                        QPixmap playPixmap(":/png/image/play.png");
//                        playPixmap = playPixmap.scaled(QSize(PLAY_ICON_WIDTH, PLAY_ICON_HEIGHT), Qt::KeepAspectRatio, Qt::SmoothTransformation);
//                        QPainter imagepainter(&pixmap);                                //新建画板
//                        imagepainter.setCompositionMode(QPainter::CompositionMode_SourceOver); //设置重叠效果
//                        imagepainter.drawPixmap((pixmap.width() - playPixmap.width()) / 2,
//                                                (pixmap.height() - playPixmap.height()) / 2, playPixmap);
//                        imagepainter.end();
//                        item->setIcon(pixmap);
//                    }
//                }
//                for (int j = 0; j < m_allPictureListView.length(); j++) {
//                    QList<FileInfo> list;
//                    m_allPictureListView[j]->selectAllNames(list);
//                    if (list.length() > 0) {
//                        Q_EMIT sigShowCopyButton();
//                        return;
//                    } else {
//                        Q_EMIT sigHideCopyToComputerWidget();
//                    }
//                }
//            }
//        });

        //设置列表模式
        connect(this, &TimeLineView::signalViewModeFlag, listView, [=](QListView::ViewMode mode) {
            listView->setViewModeFlag(mode, m_allTimeLinePicture.value(i));

            if (listView->viewMode() == QListView::IconMode) {
                viewHLayout->setContentsMargins(0, 18, 0, 0);
            } else {
                viewHLayout->setContentsMargins(20, 12, 0, 0);
            }
            if (m_allPictureAllow[i] == 0) {
                //设置高度
                Q_EMIT sigSetViewHeight();
            }
        });

        //设置view的高度
        connect(listView, &MobileFileListView::signalSetResize, this, [=](int height) {
            int h = height;
            listView->setFixedHeight(h);
            itemWidget->setFixedHeight(titleWidget->height() + h);
            item->setSizeHint(QSize(this->width(), titleWidget->height() + h));
        });

        //箭头线的点击
        connect(arrowLineButton, &QPushButton::clicked, this, [=]() {
            for (int j = 0; j < m_allPictureArrowLineButton.length(); j++) {
                if (arrowLineButton == m_allPictureArrowLineButton[j]) {
                    switch (m_allPictureAllow[j]) {
                    case 0:
                        ++m_allPictureAllow[j];
                        arrowLineButton->setIcon(QIcon(":/png/image/arrow_line_retract.png"));
                        break;
                    case 1:
                        m_allPictureAllow[j] = 0;
                        arrowLineButton->setIcon(QIcon(":/png/image/arrow_line_expand.png"));
                        break;
                    default:
                        break;
                    }

                    if (m_allPictureAllow[j] == 0) {
                        m_allPictureListView[i]->setViewHeight();
                    } else if (m_allPictureAllow[j] == 1) {
                        listView->setFixedHeight(0);
                        itemWidget->setFixedHeight(titleWidget->height() + 28);
                        item->setSizeHint(QSize(this->width(), titleWidget->height() + 28));
                    }
                }
            }
        });

        m_allPictureListView.append(listView);

        //设置当前时间线图片
        listView->setTimeLineViewData(m_allTimeLinePicture.value(i), m_itemMap);

        if (m_currentViewMode == 0) {
            listView->setViewModeFlag(QListView::IconMode, m_allTimeLinePicture.value(i));
            viewHLayout->setContentsMargins(0, 18, 0, 0);
        } else {
            listView->setViewModeFlag(QListView::ListMode, m_allTimeLinePicture.value(i));
            viewHLayout->setContentsMargins(20, 12, 0, 0);
        }

        m_pictureListWidget->addItem(item);
        m_pictureListWidget->setItemWidget(item, itemWidget);

        if (m_allPictureAllow[i] == 0) {
            //设置高度
            listView->setResize();
        }

        //要先把itemWidget添加布局，防止listView宽度是itemWidget默认宽度
        timeLineLayout->addWidget(titleWidget);
        timeLineLayout->addLayout(viewHLayout);
        timeLineLayout->setSpacing(0);
        timeLineLayout->setContentsMargins(0, 0, 0, 0);

        connect(listView, &MobileFileListView::sigShowCopyButton, this, &TimeLineView::slotShowCopyButton);

        connect(listView, &MobileFileListView::sigHideCopyToComputerWidget, this,
                &TimeLineView::slotHideCopyToComputerWidget);

        connect(listView, &MobileFileListView::sigSelectDataList, this, [=](QList<FileInfo> &fileList) {
            fileList.clear();
            for (int j = 0; j < m_allPictureListView.size(); j++) {
                QList<FileInfo> list;
                m_allPictureListView[j]->selectAllNames(list);
                fileList.append(list);
            }
            Q_EMIT sigSelectAllDataList(fileList);
        });

        connect(listView, &MobileFileListView::sigMousePress, this, [=](QMouseEvent *event) {
            m_lastRow = -1;
            if (event->button() == Qt::LeftButton) {
                for (int j = 0; j < m_allPictureListView.length(); j++) {
                    if (listView != m_allPictureListView[j]) {
                        QList<FileInfo> list;
                        m_allPictureListView[j]->selectAllNames(list);
                        m_allPictureListView[j]->clearSelection();
                        for (int k = 0; k < list.length(); k++) {
                            if (list.value(k).type() == FileInfo::FILE_TYPE::TYPE_IMAGE) {
                                QFileInfo fileInfo(list.value(k).getThumbnailPath());
                                if (fileInfo.exists()) {
                                    QStandardItem *item = m_itemMap.find(list.value(k).getThumbnailPath()).value();
                                    QString localImagePath = QString("%1").arg(list.value(k).getThumbnailPath());
                                    QPixmap pixmap(localImagePath);
                                    pixmap = pixmap.scaled(QSize(ICON_WIDTH, ICON_HEIGHT), Qt::IgnoreAspectRatio,
                                                           Qt::SmoothTransformation);
                                    item->setIcon(pixmap);
                                } else {
                                    QStandardItem *item = m_itemMap.find(list.value(k).getThumbnailPath()).value();
                                    QIcon icon = QIcon::fromTheme("image-x-generic");
                                    QPixmap pixmap(icon.pixmap(QSize(ICON_WIDTH, ICON_HEIGHT)));
                                    pixmap = pixmap.scaled(QSize(ICON_WIDTH, ICON_HEIGHT), Qt::IgnoreAspectRatio,
                                                           Qt::SmoothTransformation);
                                    item->setIcon(pixmap);
                                }
                            } else if (list.value(k).type() == FileInfo::FILE_TYPE::TYPE_VIDEO) {
                                QFileInfo fileInfo(list.value(k).getThumbnailPath());
                                if (fileInfo.exists()) {
                                    QStandardItem *item = m_itemMap.find(list.value(k).getThumbnailPath()).value();
                                    QPixmap pixmap = QString("%1").arg(list.value(k).getThumbnailPath());
                                    pixmap = pixmap.scaled(QSize(ICON_WIDTH, ICON_HEIGHT), Qt::IgnoreAspectRatio,
                                                           Qt::SmoothTransformation);
                                    QPixmap playPixmap(":/png/image/play.png");
                                    playPixmap = playPixmap.scaled(QSize(PLAY_ICON_WIDTH, PLAY_ICON_HEIGHT),
                                                                   Qt::KeepAspectRatio, Qt::SmoothTransformation);
                                    QPainter imagepainter(&pixmap); //新建画板
                                    imagepainter.setCompositionMode(
                                        QPainter::CompositionMode_SourceOver); //设置重叠效果
                                    imagepainter.drawPixmap((pixmap.width() - playPixmap.width()) / 2,
                                                            (pixmap.height() - playPixmap.height()) / 2, playPixmap);
                                    imagepainter.end();
                                    item->setIcon(pixmap);
                                } else {
                                    QStandardItem *item = m_itemMap.find(list.value(k).getThumbnailPath()).value();
                                    QPixmap pixmap(":/png/image/cover.png");
                                    pixmap = pixmap.scaled(QSize(ICON_WIDTH, ICON_HEIGHT), Qt::IgnoreAspectRatio,
                                                           Qt::SmoothTransformation);
                                    QPixmap playPixmap(":/png/image/play.png");
                                    playPixmap = playPixmap.scaled(QSize(PLAY_ICON_WIDTH, PLAY_ICON_HEIGHT),
                                                                   Qt::KeepAspectRatio, Qt::SmoothTransformation);
                                    QPainter imagepainter(&pixmap); //新建画板
                                    imagepainter.setCompositionMode(
                                        QPainter::CompositionMode_SourceOver); //设置重叠效果
                                    imagepainter.drawPixmap((pixmap.width() - playPixmap.width()) / 2,
                                                            (pixmap.height() - playPixmap.height()) / 2, playPixmap);
                                    imagepainter.end();
                                    item->setIcon(pixmap);
                                }
                            }
                        }
                    }
                }
                m_ctrlPress = false;
            }

            for (int j = 0; j < m_allPictureListView.length(); j++) {
                if (listView == m_allPictureListView[j]) {
                    m_lastClickedIndex = j;
                    m_lastRow = listView->getRow(QPoint(event->x(), event->y()));
                    QModelIndex index = listView->model()->index(m_lastRow, 0, QModelIndex());
                    FileInfo fileInfo = index.data(Qt::DisplayRole + 100).value<FileInfo>();
                    QList<FileInfo> fileList;
                    for (int k = 0; k < m_allPictureListView[j]->model()->rowCount(); k++) {
                        QModelIndex index = listView->model()->index(k, 0, QModelIndex());
                        FileInfo fileInfo = index.data(Qt::DisplayRole + 100).value<FileInfo>();
                        fileList.append(fileInfo);
                    }

                    for (int k = 0; k < fileList.size(); k++) {
                        if (fileInfo.getThumbnailPath() != fileList.value(k).getThumbnailPath()) {
                            if (fileList.value(k).type() == FileInfo::FILE_TYPE::TYPE_IMAGE) {
                                QFileInfo fileInfo(fileList.value(k).getThumbnailPath());
                                if (fileInfo.exists()) {
                                    QStandardItem *item = m_itemMap.find(fileList.value(k).getThumbnailPath()).value();
                                    QString localImagePath = QString("%1").arg(fileList.value(k).getThumbnailPath());
                                    QPixmap pixmap(localImagePath);
                                    pixmap = pixmap.scaled(QSize(ICON_WIDTH, ICON_HEIGHT), Qt::IgnoreAspectRatio,
                                                           Qt::SmoothTransformation);
                                    item->setIcon(pixmap);
                                } else {
                                    QStandardItem *item = m_itemMap.find(fileList.value(k).getThumbnailPath()).value();
                                    QIcon icon = QIcon::fromTheme("image-x-generic");
                                    QPixmap pixmap(icon.pixmap(QSize(ICON_WIDTH, ICON_HEIGHT)));
                                    pixmap = pixmap.scaled(QSize(ICON_WIDTH, ICON_HEIGHT), Qt::IgnoreAspectRatio,
                                                           Qt::SmoothTransformation);
                                    item->setIcon(pixmap);
                                }
                            } else if (fileList.value(k).type() == FileInfo::FILE_TYPE::TYPE_VIDEO) {
                                QFileInfo fileInfo(fileList.value(k).getThumbnailPath());
                                if (fileInfo.exists()) {
                                    QStandardItem *item = m_itemMap.find(fileList.value(k).getThumbnailPath()).value();
                                    QPixmap pixmap = QString("%1").arg(fileList.value(k).getThumbnailPath());
                                    pixmap = pixmap.scaled(QSize(ICON_WIDTH, ICON_HEIGHT), Qt::IgnoreAspectRatio,
                                                           Qt::SmoothTransformation);
                                    QPixmap playPixmap(":/png/image/play.png");
                                    playPixmap = playPixmap.scaled(QSize(PLAY_ICON_WIDTH, PLAY_ICON_HEIGHT),
                                                                   Qt::KeepAspectRatio, Qt::SmoothTransformation);
                                    QPainter imagepainter(&pixmap); //新建画板
                                    imagepainter.setCompositionMode(
                                        QPainter::CompositionMode_SourceOver); //设置重叠效果
                                    imagepainter.drawPixmap((pixmap.width() - playPixmap.width()) / 2,
                                                            (pixmap.height() - playPixmap.height()) / 2, playPixmap);
                                    imagepainter.end();
                                    item->setIcon(pixmap);
                                } else {
                                    QStandardItem *item = m_itemMap.find(fileList.value(k).getThumbnailPath()).value();
                                    QPixmap pixmap(":/png/image/cover.png");
                                    pixmap = pixmap.scaled(QSize(ICON_WIDTH, ICON_HEIGHT), Qt::IgnoreAspectRatio,
                                                           Qt::SmoothTransformation);
                                    QPixmap playPixmap(":/png/image/play.png");
                                    playPixmap = playPixmap.scaled(QSize(PLAY_ICON_WIDTH, PLAY_ICON_HEIGHT),
                                                                   Qt::KeepAspectRatio, Qt::SmoothTransformation);
                                    QPainter imagepainter(&pixmap); //新建画板
                                    imagepainter.setCompositionMode(
                                        QPainter::CompositionMode_SourceOver); //设置重叠效果
                                    imagepainter.drawPixmap((pixmap.width() - playPixmap.width()) / 2,
                                                            (pixmap.height() - playPixmap.height()) / 2, playPixmap);
                                    imagepainter.end();
                                    item->setIcon(pixmap);
                                }
                            }
                        }
                    }

                    if (-1 != m_lastRow)
                        m_lastChanged = true;
                }
            }
//            updateCheckBox();

            Q_EMIT sigHideCopyToComputerWidget();
        });

        connect(listView, &MobileFileListView::sigCtrlMousePress, this, [=](QMouseEvent *event) {
            m_ctrlPress = true;
            for (int j = 0; j < m_allPictureListView.length(); j++) {
                if (listView == m_allPictureListView[j]) {
                    m_lastClickedIndex = j;
                    m_lastRow = listView->getRow(QPoint(event->x(), event->y()));
                    QModelIndex index = listView->model()->index(m_lastRow, 0, QModelIndex());
                    FileInfo fileInfo = index.data(Qt::DisplayRole + 100).value<FileInfo>();
                    QList<FileInfo> fileList;
                    for (int k = 0; k < m_allPictureListView[j]->model()->rowCount(); k++) {
                        QModelIndex index = listView->model()->index(k, 0, QModelIndex());
                        FileInfo fileInfo = index.data(Qt::DisplayRole + 100).value<FileInfo>();
                        fileList.append(fileInfo);
                    }

                    for (int k = 0; k < fileList.size(); k++) {
                        if (fileInfo.getThumbnailPath() != fileList.value(k).getThumbnailPath()) {
                            if (fileList.value(k).type() == FileInfo::FILE_TYPE::TYPE_IMAGE) {
                                QFileInfo fileInfo(fileList.value(k).getThumbnailPath());
                                if (fileInfo.exists()) {
                                    QStandardItem *item = m_itemMap.find(fileList.value(k).getThumbnailPath()).value();
                                    QString localImagePath = QString("%1").arg(fileList.value(k).getThumbnailPath());
                                    QPixmap pixmap(localImagePath);
                                    pixmap = pixmap.scaled(QSize(ICON_WIDTH, ICON_HEIGHT), Qt::IgnoreAspectRatio,
                                                           Qt::SmoothTransformation);
                                    item->setIcon(pixmap);
                                } else {
                                    QStandardItem *item = m_itemMap.find(fileList.value(k).getThumbnailPath()).value();
                                    QIcon icon = QIcon::fromTheme("image-x-generic");
                                    QPixmap pixmap(icon.pixmap(QSize(ICON_WIDTH, ICON_HEIGHT)));
                                    pixmap = pixmap.scaled(QSize(ICON_WIDTH, ICON_HEIGHT), Qt::IgnoreAspectRatio,
                                                           Qt::SmoothTransformation);
                                    item->setIcon(pixmap);
                                }
                            } else if (fileList.value(k).type() == FileInfo::FILE_TYPE::TYPE_VIDEO) {
                                QFileInfo fileInfo(fileList.value(k).getThumbnailPath());
                                if (fileInfo.exists()) {
                                    QStandardItem *item = m_itemMap.find(fileList.value(k).getThumbnailPath()).value();
                                    QPixmap pixmap = QString("%1").arg(fileList.value(k).getThumbnailPath());
                                    pixmap = pixmap.scaled(QSize(ICON_WIDTH, ICON_HEIGHT), Qt::IgnoreAspectRatio,
                                                           Qt::SmoothTransformation);
                                    QPixmap playPixmap(":/png/image/play.png");
                                    playPixmap = playPixmap.scaled(QSize(PLAY_ICON_WIDTH, PLAY_ICON_HEIGHT),
                                                                   Qt::KeepAspectRatio, Qt::SmoothTransformation);
                                    QPainter imagepainter(&pixmap); //新建画板
                                    imagepainter.setCompositionMode(
                                        QPainter::CompositionMode_SourceOver); //设置重叠效果
                                    imagepainter.drawPixmap((pixmap.width() - playPixmap.width()) / 2,
                                                            (pixmap.height() - playPixmap.height()) / 2, playPixmap);
                                    imagepainter.end();
                                    item->setIcon(pixmap);
                                } else {
                                    QStandardItem *item = m_itemMap.find(fileList.value(k).getThumbnailPath()).value();
                                    QPixmap pixmap(":/png/image/cover.png");
                                    pixmap = pixmap.scaled(QSize(ICON_WIDTH, ICON_HEIGHT), Qt::IgnoreAspectRatio,
                                                           Qt::SmoothTransformation);
                                    QPixmap playPixmap(":/png/image/play.png");
                                    playPixmap = playPixmap.scaled(QSize(PLAY_ICON_WIDTH, PLAY_ICON_HEIGHT),
                                                                   Qt::KeepAspectRatio, Qt::SmoothTransformation);
                                    QPainter imagepainter(&pixmap); //新建画板
                                    imagepainter.setCompositionMode(
                                        QPainter::CompositionMode_SourceOver); //设置重叠效果
                                    imagepainter.drawPixmap((pixmap.width() - playPixmap.width()) / 2,
                                                            (pixmap.height() - playPixmap.height()) / 2, playPixmap);
                                    imagepainter.end();
                                    item->setIcon(pixmap);
                                }
                            }
                        }
                    }
                    if (-1 != m_lastRow)
                        m_lastChanged = true;
                }
            }
        });

        connect(listView, &MobileFileListView::sigShiftMousePress, this, [=](QMouseEvent *event) {
            int curClickedIndex = -1;
            int curRow = -1;
            for (int j = 0; j < m_allPictureListView.length(); j++) {
                if (listView == m_allPictureListView[j]) {
                    curClickedIndex = j;
                    curRow = listView->getRow(QPoint(event->x(), event->y()));
                    QModelIndex index = listView->model()->index(curRow, 0, QModelIndex());
                    FileInfo fileInfo = index.data(Qt::DisplayRole + 100).value<FileInfo>();
                    QList<FileInfo> fileList;
                    for (int k = 0; k < m_allPictureListView[j]->model()->rowCount(); k++) {
                        QModelIndex index = listView->model()->index(k, 0, QModelIndex());
                        FileInfo fileInfo = index.data(Qt::DisplayRole + 100).value<FileInfo>();
                        fileList.append(fileInfo);
                    }

                    for (int k = 0; k < fileList.size(); k++) {
                        if (fileInfo.getThumbnailPath() != fileList.value(k).getThumbnailPath()) {
                            if (fileList.value(k).type() == FileInfo::FILE_TYPE::TYPE_IMAGE) {
                                QFileInfo fileInfo(fileList.value(k).getThumbnailPath());
                                if (fileInfo.exists()) {
                                    QStandardItem *item = m_itemMap.find(fileList.value(k).getThumbnailPath()).value();
                                    QString localImagePath = QString("%1").arg(fileList.value(k).getThumbnailPath());
                                    QPixmap pixmap(localImagePath);
                                    pixmap = pixmap.scaled(QSize(ICON_WIDTH, ICON_HEIGHT), Qt::IgnoreAspectRatio,
                                                           Qt::SmoothTransformation);
                                    item->setIcon(pixmap);
                                } else {
                                    QStandardItem *item = m_itemMap.find(fileList.value(k).getThumbnailPath()).value();
                                    QIcon icon = QIcon::fromTheme("image-x-generic");
                                    QPixmap pixmap(icon.pixmap(QSize(ICON_WIDTH, ICON_HEIGHT)));
                                    pixmap = pixmap.scaled(QSize(ICON_WIDTH, ICON_HEIGHT), Qt::IgnoreAspectRatio,
                                                           Qt::SmoothTransformation);
                                    item->setIcon(pixmap);
                                }
                            } else if (fileList.value(k).type() == FileInfo::FILE_TYPE::TYPE_VIDEO) {
                                QFileInfo fileInfo(fileList.value(k).getThumbnailPath());
                                if (fileInfo.exists()) {
                                    QStandardItem *item = m_itemMap.find(fileList.value(k).getThumbnailPath()).value();
                                    QPixmap pixmap = QString("%1").arg(fileList.value(k).getThumbnailPath());
                                    pixmap = pixmap.scaled(QSize(ICON_WIDTH, ICON_HEIGHT), Qt::IgnoreAspectRatio,
                                                           Qt::SmoothTransformation);
                                    QPixmap playPixmap(":/png/image/play.png");
                                    playPixmap = playPixmap.scaled(QSize(PLAY_ICON_WIDTH, PLAY_ICON_HEIGHT),
                                                                   Qt::KeepAspectRatio, Qt::SmoothTransformation);
                                    QPainter imagepainter(&pixmap); //新建画板
                                    imagepainter.setCompositionMode(
                                        QPainter::CompositionMode_SourceOver); //设置重叠效果
                                    imagepainter.drawPixmap((pixmap.width() - playPixmap.width()) / 2,
                                                            (pixmap.height() - playPixmap.height()) / 2, playPixmap);
                                    imagepainter.end();
                                    item->setIcon(pixmap);
                                } else {
                                    QStandardItem *item = m_itemMap.find(fileList.value(k).getThumbnailPath()).value();
                                    QPixmap pixmap(":/png/image/cover.png");
                                    pixmap = pixmap.scaled(QSize(ICON_WIDTH, ICON_HEIGHT), Qt::IgnoreAspectRatio,
                                                           Qt::SmoothTransformation);
                                    QPixmap playPixmap(":/png/image/play.png");
                                    playPixmap = playPixmap.scaled(QSize(PLAY_ICON_WIDTH, PLAY_ICON_HEIGHT),
                                                                   Qt::KeepAspectRatio, Qt::SmoothTransformation);
                                    QPainter imagepainter(&pixmap); //新建画板
                                    imagepainter.setCompositionMode(
                                        QPainter::CompositionMode_SourceOver); //设置重叠效果
                                    imagepainter.drawPixmap((pixmap.width() - playPixmap.width()) / 2,
                                                            (pixmap.height() - playPixmap.height()) / 2, playPixmap);
                                    imagepainter.end();
                                    item->setIcon(pixmap);
                                }
                            }
                        }
                    }
                }
            }
            if (!m_lastChanged && -1 != curRow) {
                for (int j = 0; j < m_allPictureListView.length(); j++) {
                    QList<FileInfo> list;
                    m_allPictureListView[j]->selectAllNames(list);
                    m_allPictureListView[j]->clearSelection();
                    for (int k = 0; k < list.length(); k++) {
                        if (list.value(k).type() == FileInfo::FILE_TYPE::TYPE_IMAGE) {
                            QFileInfo fileInfo(list.value(k).getThumbnailPath());
                            if (fileInfo.exists()) {
                                QStandardItem *item = m_itemMap.find(list.value(k).getThumbnailPath()).value();
                                QString localImagePath = QString("%1").arg(list.value(k).getThumbnailPath());
                                QPixmap pixmap(localImagePath);
                                pixmap = pixmap.scaled(QSize(ICON_WIDTH, ICON_HEIGHT), Qt::IgnoreAspectRatio,
                                                       Qt::SmoothTransformation);
                                item->setIcon(pixmap);
                            } else {
                                QStandardItem *item = m_itemMap.find(list.value(k).getThumbnailPath()).value();
                                QIcon icon = QIcon::fromTheme("image-x-generic");
                                QPixmap pixmap(icon.pixmap(QSize(ICON_WIDTH, ICON_HEIGHT)));
                                pixmap = pixmap.scaled(QSize(ICON_WIDTH, ICON_HEIGHT), Qt::IgnoreAspectRatio,
                                                       Qt::SmoothTransformation);
                                item->setIcon(pixmap);
                            }
                        } else if (list.value(k).type() == FileInfo::FILE_TYPE::TYPE_VIDEO) {
                            QFileInfo fileInfo(list.value(k).getThumbnailPath());
                            if (fileInfo.exists()) {
                                QStandardItem *item = m_itemMap.find(list.value(k).getThumbnailPath()).value();
                                QPixmap pixmap = QString("%1").arg(list.value(k).getThumbnailPath());
                                pixmap = pixmap.scaled(QSize(ICON_WIDTH, ICON_HEIGHT), Qt::IgnoreAspectRatio,
                                                       Qt::SmoothTransformation);
                                QPixmap playPixmap(":/png/image/play.png");
                                playPixmap = playPixmap.scaled(QSize(PLAY_ICON_WIDTH, PLAY_ICON_HEIGHT),
                                                               Qt::KeepAspectRatio, Qt::SmoothTransformation);
                                QPainter imagepainter(&pixmap);                                        //新建画板
                                imagepainter.setCompositionMode(QPainter::CompositionMode_SourceOver); //设置重叠效果
                                imagepainter.drawPixmap((pixmap.width() - playPixmap.width()) / 2,
                                                        (pixmap.height() - playPixmap.height()) / 2, playPixmap);
                                imagepainter.end();
                                item->setIcon(pixmap);
                            } else {
                                QStandardItem *item = m_itemMap.find(list.value(k).getThumbnailPath()).value();
                                QPixmap pixmap(":/png/image/cover.png");
                                pixmap = pixmap.scaled(QSize(ICON_WIDTH, ICON_HEIGHT), Qt::IgnoreAspectRatio,
                                                       Qt::SmoothTransformation);
                                QPixmap playPixmap(":/png/image/play.png");
                                playPixmap = playPixmap.scaled(QSize(PLAY_ICON_WIDTH, PLAY_ICON_HEIGHT),
                                                               Qt::KeepAspectRatio, Qt::SmoothTransformation);
                                QPainter imagepainter(&pixmap);                                        //新建画板
                                imagepainter.setCompositionMode(QPainter::CompositionMode_SourceOver); //设置重叠效果
                                imagepainter.drawPixmap((pixmap.width() - playPixmap.width()) / 2,
                                                        (pixmap.height() - playPixmap.height()) / 2, playPixmap);
                                imagepainter.end();
                                item->setIcon(pixmap);
                            }
                        }
                    }
                }
            }
            if (curRow == -1 || m_lastRow == -1) {
                for (int j = 0; j < m_allPictureListView.length(); j++) {
                    QList<FileInfo> list;
                    m_allPictureListView[j]->selectAllNames(list);
                    m_allPictureListView[j]->clearSelection();
                    for (int k = 0; k < list.length(); k++) {
                        if (list.value(k).type() == FileInfo::FILE_TYPE::TYPE_IMAGE) {
                            QFileInfo fileInfo(list.value(k).getThumbnailPath());
                            if (fileInfo.exists()) {
                                QStandardItem *item = m_itemMap.find(list.value(k).getThumbnailPath()).value();
                                QString localImagePath = QString("%1").arg(list.value(k).getThumbnailPath());
                                QPixmap pixmap(localImagePath);
                                pixmap = pixmap.scaled(QSize(ICON_WIDTH, ICON_HEIGHT), Qt::IgnoreAspectRatio,
                                                       Qt::SmoothTransformation);
                                item->setIcon(pixmap);
                            } else {
                                QStandardItem *item = m_itemMap.find(list.value(k).getThumbnailPath()).value();
                                QIcon icon = QIcon::fromTheme("image-x-generic");
                                QPixmap pixmap(icon.pixmap(QSize(ICON_WIDTH, ICON_HEIGHT)));
                                pixmap = pixmap.scaled(QSize(ICON_WIDTH, ICON_HEIGHT), Qt::IgnoreAspectRatio,
                                                       Qt::SmoothTransformation);
                                item->setIcon(pixmap);
                            }
                        } else if (list.value(k).type() == FileInfo::FILE_TYPE::TYPE_VIDEO) {
                            QFileInfo fileInfo(list.value(k).getThumbnailPath());
                            if (fileInfo.exists()) {
                                QStandardItem *item = m_itemMap.find(list.value(k).getThumbnailPath()).value();
                                QPixmap pixmap = QString("%1").arg(list.value(k).getThumbnailPath());
                                pixmap = pixmap.scaled(QSize(ICON_WIDTH, ICON_HEIGHT), Qt::IgnoreAspectRatio,
                                                       Qt::SmoothTransformation);
                                QPixmap playPixmap(":/png/image/play.png");
                                playPixmap = playPixmap.scaled(QSize(PLAY_ICON_WIDTH, PLAY_ICON_HEIGHT),
                                                               Qt::KeepAspectRatio, Qt::SmoothTransformation);
                                QPainter imagepainter(&pixmap);                                        //新建画板
                                imagepainter.setCompositionMode(QPainter::CompositionMode_SourceOver); //设置重叠效果
                                imagepainter.drawPixmap((pixmap.width() - playPixmap.width()) / 2,
                                                        (pixmap.height() - playPixmap.height()) / 2, playPixmap);
                                imagepainter.end();
                                item->setIcon(pixmap);
                            } else {
                                QStandardItem *item = m_itemMap.find(list.value(k).getThumbnailPath()).value();
                                QPixmap pixmap(":/png/image/cover.png");
                                pixmap = pixmap.scaled(QSize(ICON_WIDTH, ICON_HEIGHT), Qt::IgnoreAspectRatio,
                                                       Qt::SmoothTransformation);
                                QPixmap playPixmap(":/png/image/play.png");
                                playPixmap = playPixmap.scaled(QSize(PLAY_ICON_WIDTH, PLAY_ICON_HEIGHT),
                                                               Qt::KeepAspectRatio, Qt::SmoothTransformation);
                                QPainter imagepainter(&pixmap);                                        //新建画板
                                imagepainter.setCompositionMode(QPainter::CompositionMode_SourceOver); //设置重叠效果
                                imagepainter.drawPixmap((pixmap.width() - playPixmap.width()) / 2,
                                                        (pixmap.height() - playPixmap.height()) / 2, playPixmap);
                                imagepainter.end();
                                item->setIcon(pixmap);
                            }
                        }
                    }
                }
            } else {
                if (m_lastClickedIndex < curClickedIndex) {
                    m_allPictureListView[m_lastClickedIndex]->selectRear(m_lastRow);
                    m_allPictureListView[curClickedIndex]->selectFront(curRow);
                    for (int k = m_lastClickedIndex + 1; k < curClickedIndex; k++) {
                        m_allPictureListView[k]->selectAll();
                    }
                } else if (m_lastClickedIndex > curClickedIndex) {
                    m_allPictureListView[m_lastClickedIndex]->selectFront(m_lastRow);
                    m_allPictureListView[curClickedIndex]->selectRear(curRow);
                    for (int k = curClickedIndex + 1; k < m_lastClickedIndex; k++) {
                        m_allPictureListView[k]->selectAll();
                    }
                } else if (m_lastClickedIndex == curClickedIndex) {
                    if (m_lastRow <= curRow)
                        listView->selectExtent(m_lastRow, curRow);
                    else
                        listView->selectExtent(curRow, m_lastRow);
                }
//                updateCheckBox();
                curRow = -1;
                m_lastChanged = false;
            }
        });

        connect(listView, &MobileFileListView::sigMouseRelease, this, [=]() {
            if (!m_ctrlPress) {
                for (int j = 0; j < m_allPictureListView.length(); j++) {
                    if (listView != m_allPictureListView[j]) {
                        m_allPictureListView[j]->clearSelection();
                    }
                }
            }
//            updateCheckBox();
            for (int j = 0; j < m_allPictureListView.length(); j++) {
                QList<FileInfo> list;
                m_allPictureListView[j]->selectAllNames(list);
                if (list.length() > 0) {
                    Q_EMIT sigShowCopyButton();
                }
            }
        });

        connect(listView, &MobileFileListView::sigSelectAll, this, [=]() {
            m_ctrlPress = true;
            for (int j = 0; j < m_allPictureListView.length(); j++) {
                m_allPictureListView[j]->selectAll();
            }
//            updateCheckBox();
            Q_EMIT sigShowCopyButton();
        });

        connect(listView, &MobileFileListView::sigMenuFilePath, this, [=](QString filePath) {
            Q_EMIT sigMenuFilePath(filePath);
        });

        connect(this, &TimeLineView::sigSetViewHeight, listView, [=]() {
            if (m_allPictureAllow[i] == 0) {
                //设置高度
                listView->setViewHeight();
            } else {
                listView->setFixedHeight(0);
            }

        });
    }
}

void TimeLineView::slotValueChanged(int value)
{
    int range = m_pictureListWidget->verticalScrollBar()->maximum() * SLIDER_RANGE_MOLECULE / SLIDER_RANGE_DENOMINATOR;
    if (value > range) {
        if (m_startCount == m_endCount) {
            return;
        }
        if (m_endCount < m_allPictureTimeLine.size()) {
            m_startCount = m_endCount;
            if (m_endCount + 3 > m_allPictureTimeLine.size()) {
                m_endCount = m_allPictureTimeLine.size();
            } else {
                m_endCount += 3;
            }
        } else {
            m_startCount = m_endCount;
            m_endCount = m_allPictureTimeLine.size();
        }

        setTimeLineData();
        Q_EMIT sigSetViewHeight();
    }
}

//void TimeLineView::updateCheckBox()
//{
//    for (int i = 0; i < m_allPictureCheckBox.length(); i++) {
//        QList<FileInfo> list;
//        m_allPictureListView[i]->selectAllNames(list);
//        if (m_allPictureListView[i]->model()->rowCount() == list.length()) {
//            m_allPictureCheckBox[i]->setCheckState(Qt::Checked);
//        }
//        if (m_allPictureListView[i]->model()->rowCount() != list.length() && list.length() > 0) {
//            m_allPictureCheckBox[i]->setCheckState(Qt::PartiallyChecked);
//        }
//        if (m_allPictureListView[i]->model()->rowCount() != list.length() && list.length() == 0) {
//            m_allPictureCheckBox[i]->setCheckState(Qt::Unchecked);
//        }
//    }
//}

void TimeLineView::setThumbnail(QString fileName)
{
    if (m_itemMap.contains(fileName)) {
        if (m_itemName == LIST_TYPE::VIDEO || m_itemName == LIST_TYPE::QQVIDEO
            || m_itemName == LIST_TYPE::WECHATVIDEO) { // Video视频
            QPixmap pixmapFileName = QIcon(fileName).pixmap(QSize(ICON_WIDTH, ICON_HEIGHT));
            if (pixmapFileName.isNull()) {
                for (int i = 0; i < m_allPictureListView.length(); i++) {
                    QList<FileInfo> list;
                    m_allPictureListView[i]->selectAllNames(list);
                    if (list.length() > 0) {
                        for (int j = 0; j < list.length(); j++) {
                            QStandardItem *item = m_itemMap.find(fileName).value();
                            QPixmap pixmap(":/png/image/cover.png");
                            pixmap = pixmap.scaled(QSize(ICON_WIDTH, ICON_HEIGHT), Qt::IgnoreAspectRatio,
                                                   Qt::SmoothTransformation);
                            QPixmap playPixmap(":/png/image/play.png");
                            playPixmap = playPixmap.scaled(QSize(PLAY_ICON_WIDTH, PLAY_ICON_HEIGHT),
                                                           Qt::KeepAspectRatio, Qt::SmoothTransformation);
                            QPainter imagepainter(&pixmap);                                        //新建画板
                            imagepainter.setCompositionMode(QPainter::CompositionMode_SourceOver); //设置重叠效果
                            imagepainter.drawPixmap((pixmap.width() - playPixmap.width()) / 2,
                                                    (pixmap.height() - playPixmap.height()) / 2, playPixmap);
                            imagepainter.end();

                            QPixmap selectPixmap(":/png/image/icon_select.svg");
                            selectPixmap = selectPixmap.scaled(QSize(ICON_MODE_SELECT_BUTTON, ICON_MODE_SELECT_BUTTON),
                                                               Qt::KeepAspectRatio, Qt::SmoothTransformation);
                            QPainter imagepainters(&pixmap);                                        //新建画板
                            imagepainters.setCompositionMode(QPainter::CompositionMode_SourceOver); //设置重叠效果
                            imagepainters.drawPixmap((pixmap.width() - selectPixmap.width() - 8),
                                                     (pixmap.height() - (pixmap.height() - 8)), selectPixmap);
                            imagepainters.end();
                            item->setIcon(pixmap);
                        }
                    } else {
                        QStandardItem *item = m_itemMap.find(fileName).value();
                        QPixmap pixmapFileName(fileName);
                        pixmapFileName = pixmapFileName.scaled(QSize(ICON_WIDTH, ICON_HEIGHT), Qt::IgnoreAspectRatio,
                                                               Qt::SmoothTransformation);
                        QPixmap playPixmap(":/png/image/play.png");
                        playPixmap = playPixmap.scaled(QSize(PLAY_ICON_WIDTH, PLAY_ICON_HEIGHT), Qt::KeepAspectRatio,
                                                       Qt::SmoothTransformation);
                        QPainter imagepainter(&pixmapFileName);                                //新建画板
                        imagepainter.setCompositionMode(QPainter::CompositionMode_SourceOver); //设置重叠效果
                        imagepainter.drawPixmap((pixmapFileName.width() - playPixmap.width()) / 2,
                                                (pixmapFileName.height() - playPixmap.height()) / 2, playPixmap);
                        imagepainter.end();
                        item->setIcon(pixmapFileName);
                    }
                }
            } else {
                for (int i = 0; i < m_allPictureListView.length(); i++) {
                    QList<FileInfo> list;
                    m_allPictureListView[i]->selectAllNames(list);
                    if (list.length() > 0) {
                        for (int j = 0; j < list.length(); j++) {
                            QStandardItem *item = m_itemMap.find(fileName).value();
                            pixmapFileName = pixmapFileName.scaled(QSize(ICON_WIDTH, ICON_HEIGHT),
                                                                   Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
                            QPixmap playPixmap(":/png/image/play.png");
                            playPixmap = playPixmap.scaled(QSize(PLAY_ICON_WIDTH, PLAY_ICON_HEIGHT),
                                                           Qt::KeepAspectRatio, Qt::SmoothTransformation);
                            QPainter imagepainter(&pixmapFileName);                                //新建画板
                            imagepainter.setCompositionMode(QPainter::CompositionMode_SourceOver); //设置重叠效果
                            imagepainter.drawPixmap((pixmapFileName.width() - playPixmap.width()) / 2,
                                                    (pixmapFileName.height() - playPixmap.height()) / 2, playPixmap);
                            imagepainter.end();
                            QPixmap selectPixmap(":/png/image/icon_select.svg");
                            selectPixmap = selectPixmap.scaled(QSize(ICON_MODE_SELECT_BUTTON, ICON_MODE_SELECT_BUTTON),
                                                               Qt::KeepAspectRatio, Qt::SmoothTransformation);
                            QPainter imagepainters(&pixmapFileName);                                //新建画板
                            imagepainters.setCompositionMode(QPainter::CompositionMode_SourceOver); //设置重叠效果
                            imagepainters.drawPixmap((pixmapFileName.width() - selectPixmap.width() - 8),
                                                     (pixmapFileName.height() - (pixmapFileName.height() - 8)),
                                                     selectPixmap);
                            imagepainters.end();
                            item->setIcon(pixmapFileName);
                        }
                    } else {
                        QStandardItem *item = m_itemMap.find(fileName).value();
                        QPixmap pixmapFileName(fileName);
                        pixmapFileName = pixmapFileName.scaled(QSize(ICON_WIDTH, ICON_HEIGHT), Qt::IgnoreAspectRatio,
                                                               Qt::SmoothTransformation);
                        QPixmap playPixmap(":/png/image/play.png");
                        playPixmap = playPixmap.scaled(QSize(PLAY_ICON_WIDTH, PLAY_ICON_HEIGHT), Qt::KeepAspectRatio,
                                                       Qt::SmoothTransformation);
                        QPainter imagepainter(&pixmapFileName);                                //新建画板
                        imagepainter.setCompositionMode(QPainter::CompositionMode_SourceOver); //设置重叠效果
                        imagepainter.drawPixmap((pixmapFileName.width() - playPixmap.width()) / 2,
                                                (pixmapFileName.height() - playPixmap.height()) / 2, playPixmap);
                        imagepainter.end();
                        item->setIcon(pixmapFileName);
                    }
                }
            }
        } else {
            if (m_itemName == LIST_TYPE::PICTURE || m_itemName == LIST_TYPE::QQPICTURE
                || m_itemName == LIST_TYPE::WECHATPICTURE) { // Picture视频
                QStandardItem *item = m_itemMap.find(fileName).value();
                QPixmap pixmapFileName = QIcon(fileName).pixmap(QSize(ICON_WIDTH, ICON_HEIGHT));
                if (pixmapFileName.isNull()) {
                    for (int i = 0; i < m_allPictureListView.length(); i++) {
                        QList<FileInfo> list;
                        m_allPictureListView[i]->selectAllNames(list);
                        if (list.length() > 0) {
                            for (int j = 0; j < list.length(); j++) {
                                QIcon icon = QIcon::fromTheme("image-x-generic");
                                QPixmap pixmap(icon.pixmap(QSize(ICON_WIDTH, ICON_HEIGHT)));
                                pixmap = pixmap.scaled(QSize(ICON_WIDTH, ICON_HEIGHT), Qt::IgnoreAspectRatio,
                                                       Qt::SmoothTransformation);
                                QPixmap selectPixmap(":/png/image/icon_select.svg");
                                selectPixmap =
                                    selectPixmap.scaled(QSize(ICON_MODE_SELECT_BUTTON, ICON_MODE_SELECT_BUTTON),
                                                        Qt::KeepAspectRatio, Qt::SmoothTransformation);
                                QPainter imagepainter(&pixmap);                                        //新建画板
                                imagepainter.setCompositionMode(QPainter::CompositionMode_SourceOver); //设置重叠效果
                                imagepainter.drawPixmap((pixmap.width() - selectPixmap.width() - 8),
                                                        (pixmap.height() - (pixmap.height() - 8)), selectPixmap);
                                imagepainter.end();
                                item->setIcon(pixmap);
                            }
                        } else {
                            QPixmap pixmap = QIcon(fileName).pixmap(QSize(ICON_WIDTH, ICON_HEIGHT));
                            pixmap = pixmap.scaled(QSize(ICON_WIDTH, ICON_HEIGHT), Qt::IgnoreAspectRatio,
                                                   Qt::SmoothTransformation);
                            item->setIcon(pixmap);
                        }
                    }
                } else {
                    for (int i = 0; i < m_allPictureListView.length(); i++) {
                        QList<FileInfo> list;
                        m_allPictureListView[i]->selectAllNames(list);
                        if (list.length() > 0) {
                            for (int j = 0; j < list.length(); j++) {
                                pixmapFileName = pixmapFileName.scaled(QSize(ICON_WIDTH, ICON_HEIGHT),
                                                                       Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
                                QPixmap selectPixmap(":/png/image/icon_select.svg");
                                selectPixmap =
                                    selectPixmap.scaled(QSize(ICON_MODE_SELECT_BUTTON, ICON_MODE_SELECT_BUTTON),
                                                        Qt::KeepAspectRatio, Qt::SmoothTransformation);
                                QPainter imagepainter(&pixmapFileName);                                //新建画板
                                imagepainter.setCompositionMode(QPainter::CompositionMode_SourceOver); //设置重叠效果
                                imagepainter.drawPixmap((pixmapFileName.width() - selectPixmap.width() - 8),
                                                        (pixmapFileName.height() - (pixmapFileName.height() - 8)),
                                                        selectPixmap);
                                imagepainter.end();
                                item->setIcon(pixmapFileName);
                            }
                        } else {
                            QPixmap pixmap = QIcon(fileName).pixmap(QSize(ICON_WIDTH, ICON_HEIGHT));
                            pixmap = pixmap.scaled(QSize(ICON_WIDTH, ICON_HEIGHT), Qt::IgnoreAspectRatio,
                                                   Qt::SmoothTransformation);
                            item->setIcon(pixmap);
                        }
                    }
                }
            } else {
                QStandardItem *item = m_itemMap.find(fileName).value();
                QPixmap pixmap = QIcon(fileName).pixmap(QSize(ICON_WIDTH, ICON_HEIGHT));
                pixmap = pixmap.scaled(QSize(ICON_WIDTH, ICON_HEIGHT), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
                item->setIcon(pixmap);
            }
        }
    }
}

void TimeLineView::setViewHeight()
{
    Q_EMIT sigSetViewHeight();
}

void TimeLineView::setMode(QListView::ViewMode mode)
{
    Q_EMIT signalViewModeFlag(mode);
}

void TimeLineView::setCurrentViewMode(int currentIndex)
{
    qInfo() << "change mode set current : " << currentIndex;
    m_currentViewMode = currentIndex;
}

void TimeLineView::setTimeLineData(const QList<FileInfo> &listStruct)
{
    if (listStruct.size() == 0) {
        QVBoxLayout *vLayout = new QVBoxLayout();
        m_pictureListWidget->setLayout(vLayout);

        QWidget *hWidget = new QWidget(this);
        vLayout->addStretch();
        vLayout->addWidget(hWidget);
        vLayout->addStretch();

        QHBoxLayout *hLayout = new QHBoxLayout();
        hWidget->setLayout(hLayout);
        QLabel *label = new QLabel(this);
        label->setText(tr("No file")); // No file无文件
        hLayout->addStretch();
        hLayout->addWidget(label);
        hLayout->addStretch();
    } else {
        m_listStruct = listStruct;
    }
}

void TimeLineView::setData(const QList<FileInfo> &listStruct)
{
    if (listStruct.size() == 0) {
        QVBoxLayout *vLayout = new QVBoxLayout();
        this->setLayout(vLayout);

        QWidget *hWidget = new QWidget(this);
        vLayout->addStretch();
        vLayout->addWidget(hWidget);
        vLayout->addStretch();

        QHBoxLayout *hLayout = new QHBoxLayout();
        hWidget->setLayout(hLayout);
        QLabel *label = new QLabel(this);
        label->setText(tr("No file")); // No file无文件
        hLayout->addStretch();
        hLayout->addWidget(label);
        hLayout->addStretch();
    } else {
        m_listStruct = listStruct;
    }
}

void TimeLineView::slotShowCopyButton()
{
    Q_EMIT sigShowCopyButton();
}

void TimeLineView::slotHideCopyToComputerWidget()
{
    Q_EMIT sigHideCopyToComputerWidget();
}

void TimeLineView::slotSelectDataList(const QList<FileInfo> &fileList)
{
    Q_EMIT sigSelectDataList(fileList);
}
